<?php

/**
 * This is the model class for table "parner".
 *
 * The followings are the available columns in table 'parner':
 * @property integer $id
 * @property string $diachi
 * @property string $phone
 * @property string $fax
 * @property string $email
 * @property string $website
 * @property string $tencongty
 * @property integer $flag
 * @property string $gioithieu
 * @property string $nhanhieu
 * @property string $sanpham
 * @property string $tinquangcao
 * @property string $logo
 */
class Parner extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'parner';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('diachi, tencongty, flag, logo,uid,url,cate_id,ctiID,pr_stardate, pr_enddate', 'required'),
			array('flag,uid,code,cate_id,ctiID,discount', 'numerical', 'integerOnly'=>true),
                        array('url', 'unique', 'message' => 'Tên hiễn thị Url này đã tồn tại'),
			array('diachi, email, website', 'length', 'max'=>300),
                        array('discription, keyword', 'length', 'max'=>500),
			array('phone, fax, logo,photo', 'length', 'max'=>50),
			array('tencongty,url', 'length', 'max'=>200),
			array('gioithieu, nhanhieu, sanpham, tinquangcao,chungnhan,tuyendung', 'safe'),
                        array('logo,photo', 'file', 'types' => 'jpeg,jpg, gif, png', 'maxSize' => 70000, 'allowEmpty' => true, 'tooLarge' => 'Hình ảnh không được vượt quá 70kb. Bạn phải giảm dung lượng file ảnh .'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, diachi, phone, fax, email, website, tencongty, flag, gioithieu, nhanhieu, sanpham, tinquangcao, logo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'diachi' => 'Địa chỉ',
			'phone' => 'Phone',
			'fax' => 'Fax',
			'email' => 'Email',
			'website' => 'Website',
			'tencongty' => 'Tên công ty',
			'flag' => 'Trạng thái',
			'gioithieu' => 'Giới thiệu',
			'nhanhieu' => 'Bản đồ',
			'sanpham' => 'Sản phẩm/Dịch vụ',
			'tinquangcao' => 'Khuyến mãi',
                        'chungnhan'=>'Chứng Nhận',
			'logo' => 'Logo (162x62)',
                        'photo' => 'Hình (190x205)',
                        'uid' => 'UID',
                        'url' => 'Tên hiễn thị Url',
                        'discription'=>'Mô tả ngắn',
                        'keyword'=>'Từ khóa',
                        'cate_id'=>'Danh mục',
                        'ctiID'=>'Thành phố',
                        'pr_stardate'=>'Ngày bắt đầu', 
                    'pr_enddate'=>'Ngày kết thúc',
                    'Hình thức'=>'Giảm giá',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('diachi',$this->diachi,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('fax',$this->fax,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('website',$this->website,true);
		$criteria->compare('tencongty',$this->tencongty,true);
		$criteria->compare('flag',$this->flag);
		$criteria->compare('gioithieu',$this->gioithieu,true);
		$criteria->compare('nhanhieu',$this->nhanhieu,true);
		$criteria->compare('sanpham',$this->sanpham,true);
		$criteria->compare('tinquangcao',$this->tinquangcao,true);
		$criteria->compare('logo',$this->logo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Parner the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
